home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / misc / gms_joyports.lha / JoyPorts / joyports.c < prev    next >
C/C++ Source or Header  |  1998-10-10  |  8KB  |  217 lines

  1. /*
  2. ** Module:    JoyPorts.
  3. ** Type:      Object based hardware driver.
  4. ** Author:    Paul Manias
  5. ** Copyright: DreamWorld Productions (c) 1996-1998.  All rights reserved.
  6. **
  7. ** --------------------------------------------------------------------------
  8. ** 
  9. ** TERMS AND CONDITIONS
  10. ** 
  11. ** This source code is made available on the condition that it is only used to
  12. ** further enhance the Games Master System.  IT IS NOT DISTRIBUTED FOR THE USE
  13. ** IN OTHER PRODUCTS.  Developers may edit and re-release this source code
  14. ** only in the form of its GMS module.  Use of this code outside of the module
  15. ** is not permitted under any circumstances.
  16. ** 
  17. ** This source code stays the copyright of DreamWorld Productions regardless
  18. ** of what changes or additions are made to it by 3rd parties.  However joint
  19. ** copyright is granted if the 3rd party wishes to retain some ownership of
  20. ** said modifications.
  21. ** 
  22. ** In exchange for our distribution of this source code, we also ask you to
  23. ** distribute the source when releasing a modified version of this module.
  24. ** This is not compulsory if any additions are sensitive to 3rd party
  25. ** copyrights, or if it would damage any commercial product(s).
  26. ** 
  27. ** --------------------------------------------------------------------------
  28. **
  29. ** BUGS AND MISSING FEATURES
  30. ** -------------------------
  31. ** If you correct a bug or fill in a missing feature, the source should be
  32. ** e-mailed to pmanias@ihug.co.nz for inclusion in the next update of this
  33. ** module.
  34. **
  35. ** The following issues need attention:
  36. **
  37. ** + Joypad, Segapad and Analogue support.  There used to be full joypad and
  38. **   sega support but it was never confirmed that it worked, so it was removed.
  39. **
  40. ** + The hardware bits for some of the mouse/joystick buttons are not set
  41. **   correctly, these need to be fixed and tested.
  42. **
  43. ** + Support a Qualifier mask for keyboard based emulation.  This will allow
  44. **   the player to select between normal keyboard input and joystick input (vital
  45. **   for mouse based games that support the keyboard).  Also, support a
  46. **   switching feature, so that the user can flip between modes at the press of
  47. **   a key.
  48. **
  49. ** + Grab joydata timeouts from user prefs rather than using the default.
  50. **
  51. ** + Buttons need to be buffered so that there is a point to the time-out field.
  52. **   The time since the last Activate()/Query() should also be stored in the
  53. **   JoyData structure so that we can assess when the last read was.
  54. **
  55. ** + If it is necessary to calibrate analog joysticks (find the most extreme
  56. **   value that can be returned for each direction) we will need to do this
  57. **   from GMSPrefs.
  58. **
  59. ** CHANGES
  60. ** -------
  61. ** 12 Jan Added new fields - ButtonTimeOut, MoveTimeOut.
  62. ** 21 Jan Bug in Joystick reader not resetting coordinates to null, fixed.
  63. ** 22 Jan New fields added, *Limit.
  64. ** 06 Feb Added support for GVBase->UserFocus. [Activate() altered]
  65. ** 14 Feb Altered port initialisation.
  66. **        Keyboard emulation support is working.
  67. ** 26 Apr Now written entirely in C.
  68. ** 14 Jun Removed the "DATA=faronly" option from SAS/C and recompiled - looks okay.
  69. **        Tested the DCC compilation, worked fine.
  70. ** 10 Oct Added support for JPORT_DIGITAL and JPORT_ANALOGUE in Port field.
  71. */
  72.  
  73. #include <proto/dpkernel.h>
  74. #include <system/all.h>
  75. #include <input/keyboard.h>
  76. #include <hardware/custom.h>
  77. #include <hardware/cia.h>
  78. #include <dpkernel/prefs.h>
  79.  
  80. extern struct SysObject *JoyObject;
  81. extern struct GVBase    *GVBase;
  82. extern struct Custom    *custom;
  83. extern struct CIA       *cia;
  84. extern struct ModPublic *Public;
  85.  
  86. /************************************************************************************
  87. ** Internal proto-types.
  88. */
  89.  
  90. void FreeModule(void);
  91. void ReadAnalogue(struct JoyData *);
  92. void ReadJoyPad(struct JoyData *);
  93. void ReadJoyStick(struct JoyData *);
  94. void ReadKeyboard(struct JoyData *);
  95. void ReadMouse(struct JoyData *);
  96. void ReadSegaPad(struct JoyData *);
  97.  
  98. LIBFUNC LONG             JOY_Activate(mreg(__a0) struct JoyData *);
  99. LIBFUNC struct JoyData * JOY_Get(mreg(__a0) struct Stats *);
  100. LIBFUNC LONG             JOY_Init(mreg(__a0) struct JoyData *);
  101. LIBFUNC void             JOY_Free(mreg(__a0) struct JoyData *);
  102.  
  103. #define JOY_FIELDS 11
  104.  
  105. struct Field JoyFields[JOY_FIELDS] = {
  106.   { "Port",          12, FID_Port,          FDF_WORD, 0, 0, NULL, NULL },
  107.   { "XChange",       14, FID_XChange,       FDF_WORD|FDF_RANGE, -1000, +1000, NULL, NULL },
  108.   { "YChange",       16, FID_YChange,       FDF_WORD|FDF_RANGE, -1000, +1000, NULL, NULL },
  109.   { "ZChange",       18, FID_ZChange,       FDF_WORD|FDF_RANGE, -1000, +1000, NULL, NULL }, 
  110.   { "Buttons",       20, FID_Buttons,       FDF_LONG, 0, 0, NULL, NULL },
  111.   { "ButtonTimeOut", 24, FID_ButtonTimeOut, FDF_WORD|FDF_RANGE, 0, 32000, NULL, NULL },
  112.   { "MoveTimeOut",   26, FID_MoveTimeOut,   FDF_WORD|FDF_RANGE, 0, 32000, NULL, NULL },
  113.   { "NXLimit",       28, FID_NXLimit,       FDF_WORD, 0, 0, NULL, NULL },
  114.   { "NYLimit",       30, FID_NYLimit,       FDF_WORD, 0, 0, NULL, NULL },
  115.   { "PXLimit",       32, FID_PXLimit,       FDF_WORD, 0, 0, NULL, NULL },
  116.   { "PYLimit",       34, FID_PYLimit,       FDF_WORD, 0, 0, NULL, NULL },
  117. };
  118.  
  119. BYTE ModAuthor[]    = "Paul Manias";
  120. BYTE ModDate[]      = "September 1998";
  121. BYTE ModCopyright[] = "DreamWorld Productions (c) 1996-1998.  All rights reserved.";
  122. BYTE ModName[]      = "Joyports";
  123.  
  124. /************************************************************************************
  125. ** Command: Init()
  126. ** Short:   Called when our module is being opened for the first time.  Any
  127. **          allocations made here will need to be freed in the FreeModule()
  128. **          function.
  129. */
  130.  
  131. LIBFUNC LONG CMDInit(mreg(__a0) LONG argModule,
  132.                      mreg(__a1) LONG argDPKBase,
  133.                      mreg(__a2) LONG argGVBase,
  134.                      mreg(__d0) LONG argDPKVersion,
  135.                      mreg(__d1) LONG argDPKRevision)
  136. {
  137.   DPKBase = (APTR)argDPKBase;
  138.   GVBase  = (struct GVBase *)argGVBase;
  139.   Public  = ((struct Module *)argModule)->Public;
  140.  
  141.   if ((argDPKVersion < DPKVersion) OR
  142.      ((argDPKVersion IS DPKVersion) AND (argDPKRevision < DPKRevision))) {
  143.      DPrintF("!Init:","This module requires a newer version of the dpkernel library.");
  144.      return(ERR_FAILED);
  145.   }
  146.  
  147.   if (!(JoyObject = AddSysObjectTags(ID_JOYDATA, ID_JOYDATA, "JoyData",
  148.         TAGS,           NULL,
  149.         SOA_Activate,   JOY_Activate,
  150.         SOA_Free,       JOY_Free,
  151.         SOA_Get,        JOY_Get,
  152.         SOA_Init,       JOY_Init,
  153.         SOA_Query,      JOY_Activate,
  154.         SOA_FieldArray, &JoyFields,
  155.         SOA_FieldTotal, JOY_FIELDS,
  156.         SOA_FieldSize,  sizeof(struct Field),
  157.         TAGEND))) {
  158.      FreeModule();
  159.      return(ERR_FAILED);
  160.   }
  161.  
  162.   return(ERR_OK);
  163. }
  164.  
  165. /************************************************************************************
  166. ** Command: Open()
  167. ** Short:   Called when our module is being opened for a second time...
  168. */
  169.  
  170. LIBFUNC LONG CMDOpen(mreg(__a0) struct Module *Module)
  171. {
  172.   Public->OpenCount++;
  173.   return(ERR_OK);
  174. }
  175.  
  176. /************************************************************************************
  177. ** Command: Expunge()
  178. ** Short:   Called on expunge - if no program has us opened then we can give
  179. **          permission to have us shut down.
  180. */
  181.  
  182. LIBFUNC LONG CMDExpunge(void)
  183. {
  184.   if (Public) {
  185.      if (Public->OpenCount IS NULL) {
  186.         FreeModule();
  187.         return(ERR_OK); /* Okay to expunge */
  188.      }
  189.   }
  190.   else DPrintF("!Joyports:","I have no Public base reference.");
  191.  
  192.   return(ERR_FAILED); /* Do not expunge */
  193. }
  194.  
  195. /************************************************************************************
  196. ** Command: Close()
  197. ** Short:   Called whenever someone is closing a link to our module.
  198. */
  199.  
  200. LIBFUNC void CMDClose(mreg(__a0) struct Module *Module)
  201. {
  202.   Public->OpenCount--;
  203. }
  204.  
  205. /************************************************************************************
  206. ** Internal: FreeModule()
  207. ** Short:    Frees any allocations made in the initialisation of our module.
  208. */
  209.  
  210. void FreeModule(void)
  211. {
  212.   if (JoyObject) RemSysObject(JoyObject);
  213. }
  214.  
  215. #include "JOY_Init.c"
  216.  
  217.